import axios from 'axios'

// 支持 window 变量动态配置后端地址
const baseURL = window.APP_CONFIG?.BASE_API || '/api'
console.log(baseURL)
// 创建axios实例
const service = axios.create({
  baseURL,
  timeout: 5000
})

/**
 * 获取日程列表
 * @param {*} params 
 * @returns 
 */
export function getScheduleList(params) {
  return service({
    url: '/todo/list',
    method: 'get',
    params
  })
}

// 获取单个日程详情
export function getScheduleDetail(id) {
  return service({
    url: `/todo/detail/${id}`,
    method: 'get'
  })
}

// 创建新日程
export function createSchedule(data) {
  return service({
    url: '/todo/insert',
    method: 'post',
    data
  })
}

// 更新日程
export function updateSchedule(data) {
  return service({
    url: `/todo/update`,
    method: 'post',
    data
  })
}

// 删除日程
export function deleteSchedule(id) {
  return service({
    url: `/todo/delete/${id}`,
    method: 'post'
  })
}

// 批量删除日程
export function batchDeleteSchedule(ids) {
  return service({
    url: '/todo/schedules/batch',
    method: 'delete',
    data: { ids }
  })
}

// 更新日程状态
export function updateScheduleStatus(id, status) {
  return service({
    url: `/schedules/${id}/status`,
    method: 'patch',
    data: { status }
  })
}

// 获取日程统计数据
export function getSchedulePage(data) {
  return service({
    url: '/todo/page',
    method: 'post',
    data
  })
}

// 获取逆向日程表
export function getReverseList(data) {
  return service({
    url: '/todo/reverseList',
    method: 'post',
    data
  })
}

// 获取标签列表
export function getScheduleTagList() {
  return service({
    url: '/todo/tagList',
    method: 'get'
  })
}

// 获取推荐列表
export function getRecommend(data) {
  return service({
    url: '/todo/recommend',
    method: 'post',
    data
  })
}

// 获取推荐列表
export function getReverseRecommend(data) {
  return service({
    url: '/todo/reverseRecommend',
    method: 'post',
    data
  })
}

// 获取积分
export function getPoint(tagId) {
  return service({
    url: '/todo/getPoint',
    method: 'get',
    params: { tagId }
  })
}

// 获取时间详情
export function getDetail() {
  return service({
    url: '/todo/getDetail',
    method: 'get'
  })
}

// 消费时间
export function consume(data) {
  return service({
    url: '/todo/consume',
    method: 'post',
    data
  })
}

// 时间分期
export function savePayment(data) {
  return service({
    url: '/todo/savePayment',
    method: 'post',
    data
  })
}
// 获取日程统计
export function getCensus(data) {
  return service({
    url: '/todo/census',
    method: 'post',
    data
  })
}
// 获取首页
export function homeDetails(data) {
  return service({
    url: '/todo/homeDetails',
    method: 'post',
    data
  })
}

// 获取首页
export function homeHeader(data) {
  return service({
    url: '/todo/homeHeader',
    method: 'post',
    data
  })
}

// 获取感受统计
export function getCensusByFeeling(data) {
  return service({
    url: '/todo/censusByFeeling',
    method: 'post',
    data
  })
}
